package com.itheima.behaviour.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.behaviour.pojo.ApBehaviorEntry;
import com.itheima.behaviour.mapper.ApBehaviorEntryMapper;
import com.itheima.behaviour.service.ApBehaviorEntryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * APP行为实体表,一个行为实体可能是用户或者设备，或者其它 服务实现类
 * </p>
 *
 * @author 作者
 * @since 2021-08-30
 */
@Service
public class ApBehaviorEntryServiceImpl extends ServiceImpl<ApBehaviorEntryMapper, ApBehaviorEntry> implements ApBehaviorEntryService {

    @Autowired
    private ApBehaviorEntryMapper apBehaviorEntryMapper;

    /**
     * 根据ID（设备机器号|userId）查询用户信息（游客、系统会员）
     */
    @Override
    public ApBehaviorEntry getByEquipmentIdOrUserId(Integer equipmentId, Integer userId) {
        //类型：默认查询会员
        //entry_id:默认=userId
        Integer type = 1;
        Integer entryId=userId;
        if(userId==null){
            //根据设备机器号（游客）查询
            type=0;
            entryId=equipmentId;
        }
        QueryWrapper<ApBehaviorEntry> queryWrapper = new QueryWrapper<ApBehaviorEntry>();
        queryWrapper.eq("type",type);
        queryWrapper.eq("entry_id",entryId);
        ApBehaviorEntry entry = apBehaviorEntryMapper.selectOne(queryWrapper);
        return entry;
    }
}
